#ifndef MODBUSSERVER_H
#define MODBUSSERVER_H

#include <QObject>
#include <QModbusServer>

class ModbusServer : public QObject
{
    Q_OBJECT
public:
    explicit ModbusServer(QObject *parent = nullptr);
    ~ModbusServer();
    void setValue(const QString &name, const QVariant& value);

    void Open(QString ipaddress);
    void Close();

signals:
    void newDataReady(const QString &name, const QVariant& value);

private Q_SLOTS:
    void onStateChanged(int state);
    void onRegisterChanged(QModbusDataUnit::RegisterType table, int address, int size);
    void handleDeviceError(QModbusDevice::Error newError);

private:
    QModbusServer *modbusDevice;
    qint64 OK=0;
    qint64 NG=0;
};

#endif // MODBUSSERVER_H
